<!doctype html>
<html lang="zh">

	<head>
		<meta charset="UTF-8" />
		<title>淘抢购</title>
		<link rel="stylesheet" type="text/css" href="new_file.css"/>
	</head>

				
				
			<img id="go" src="img/lago.png"/>
			<button id="btn">换一换</button> <a href="">更多></a>
				<hr />
			<div id="list">
				
			</div>

	<body>
		<script type="text/javascript">
			var aa = 1;
			var btn = document.querySelector("#btn").addEventListener('click',function(){
				
				if(aa<=2){
					
					aa++;
				}else{
						aa = 1;
				}
					document.querySelector("#list").innerHTML = '';
					loadXMLDoc();
				
				
				
			})
			
			function loadXMLDoc() {
				var xmlhttp;
				if(window.XMLHttpRequest) {
					//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
					xmlhttp = new XMLHttpRequest();
				} else {
					// IE6, IE5 浏览器执行代码
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}
				xmlhttp.onreadystatechange = function() {
					if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
						var json = xmlhttp.responseText;
						json = JSON.parse(json);
						
						for(let i = 0; i < json.tqg.length; i++){
							
//							创建节点
							var img = document.createElement('img');
							img.src = json.tqg[i].pic;
							
//							创建h3节点
							var h3 = document.createElement('h3');
							h3.innerHTML = json.tqg[i].title;
							
//							创建p节点
							
							var p = document.createElement('p');
							p.innerHTML = json.tqg[i].price;
							
//							创建s节点
							var s = document.createElement('s');
							s.innerHTML = json.tqg[i].jiange;
							console.log(s)
//							创建div节点

							div = document.createElement('div');
							div.appendChild(img)
							div.appendChild(h3)
							div.appendChild(p)
							p.appendChild(s)
							console.log(div);
							document.querySelector("#list").appendChild(div);
						}
						
						
						
//						console.log(json.tqg);
						//document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
					}
				}
				xmlhttp.open("GET", aa + ".json", true);
				xmlhttp.send();
			}
			loadXMLDoc();
		</script>
	</body>

</html>